package com.hee.erp.modules.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.City;
import com.hee.erp.modules.entity.Province;
import com.hee.erp.modules.service.ICityService;
import com.hee.erp.modules.service.IProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/modules/region")
@Api(tags = "RegionController")
public class RegionController {

    @Autowired
    IProvinceService provinceService;

    @Autowired
    ICityService cityService;

    @GetMapping("/getAllProvinceList")
    @ApiOperation("/getAllProvinceList")
    public R getAllProvinceList() {
        List<Province> list = provinceService.list();
        return R.success(list);
    }


    @GetMapping("/getCityListByProvinceId")
    @ApiOperation("/getCityListByProvinceId")
    public R getCityListByProvinceId(String provinceId) {
        LambdaQueryWrapper<City> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(City::getProvinceId, provinceId);
        List<City> list = cityService.list(queryWrapper);
        return R.success(list);
    }
}
